// 光柱

export default class LlightColumn {
    constructor() {
        this.length = 0;
        this.index = 0;
        this.DataSource = null;
    }
    init(positions) {

        viewer.scene.globe.depthTestAgainstTerrain = false;
        // viewer.dataSources.removeAll();
        // 清楚所有光柱  未写

        this.DataSource = new Cesium.CustomDataSource('LlightColumnEntities');
        this.length = positions.length;
        this.index = 0;

        this.drawAllBar(positions);
    }
    drawAllBar(positions) {
        // this.drawSingleBar(positions[this.index][0], positions[this.index][1])
        positions.forEach(item => {
            this.drawSingleBar(item[0], item[1]);
            // this.getHeigthByLonLat(item[0], item[1])
        })
        viewer.dataSources.add(this.DataSource);
    }
    drawSingleBar(lon, lat) {
        var positions = Cesium.Cartographic.fromDegrees(lon, lat);
        var promise = new Cesium.sampleTerrain(viewer.terrainProvider, 13, [positions]);
        promise = Cesium.sampleTerrainMostDetailed(viewer.terrainProvider, positions);
        Cesium.when(new Cesium.sampleTerrain(viewer.terrainProvider, 13, [positions]), (updatedPositions) => {
            const h = updatedPositions[0].height
            // this.DataSource.entities.add({
            //     name: "plane",
            //     position: Cesium.Cartesian3.fromDegrees(lon, lat, h),
            //     plane: {
            //         plane: new Cesium.Plane(Cesium.Cartesian3.UNIT_Z, 0),//指定平面的法线和距离
            //         dimensions: new Cesium.Cartesian2(400.0, 300.0),//指定平面的宽度和高度。
            //         material: new Cesium.ImageMaterialProperty({
            //             image: require("../../assets/materialImg/dad.png"), // 'http://localhost:8888/model/SampleData/image.jpg',//图片
            //             // color: Cesium.Color.BLUE/*.withAlpha(0.2)*/,//颜色
            //             transparent: 0.8,//颜色透明度
            //             repeat: new Cesium.Cartesian2(1, 1)//s,t方向重复次数
            //         }),//图片材质
            //         cornerType: Cesium.CornerType.BEVELED,
            //         fill: true,//是否填充
            //     },
            // });
            this.DataSource.entities.add({
                position: Cesium.Cartesian3.fromDegrees(lon, lat, h),
                billboard: {
                    image: require("../../assets/materialImg/dad.png"),  // "../../../asset/materialImg/line-markder.png",
                    width: 60,
                    height: 40,
                    sizeInMaters: true,
                }
            })

            // entity.billboard.disableDepthTestDistance = Number.POSITIVE_INFINITY; //去掉地形遮挡
            // this.DataSource.entities.add({
            //     name: "plane",
            //     position: Cesium.Cartesian3.fromDegrees(lon, lat, h + h / 2),
            //     plane: {
            //         plane: new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0),//指定平面的法线和距离
            //         dimensions: new Cesium.Cartesian2(400.0, 1200.0),//指定平面的宽度和高度。
            //         material: new Cesium.ImageMaterialProperty({
            //             image: require("../../assets/materialImg/2595.png"), // 'http://localhost:8888/model/SampleData/image.jpg',//图片
            //             // color: Cesium.Color.BLUE/*.withAlpha(0.2)*/,//颜色
            //             transparent: 0.8,//颜色透明度
            //             repeat: new Cesium.Cartesian2(1, 1)//s,t方向重复次数
            //         }),//图片材质
            //         fill: true,//是否填充
            //         cornerType: Cesium.CornerType.BEVELED,
            //     },
            // });
            // viewer.flyTo(entity)
            viewer.flyTo(this.DataSource);


        });





    }
    getHeigthByLonLat(lon, lat) {
        var positions = Cesium.Cartographic.fromDegrees(lon, lat);
        var promise = new Cesium.sampleTerrain(viewer.terrainProvider, 13, [positions]);
        promise = Cesium.sampleTerrainMostDetailed(viewer.terrainProvider, positions);
        Cesium.when(new Cesium.sampleTerrain(viewer.terrainProvider, 13, [positions]), function (updatedPositions) {
            viewer.entities.add({
                position: Cesium.Cartesian3.fromDegrees(lon, lat, updatedPositions[0].height),
                point: {
                    color: Cesium.Color.DARKORANGE,
                    pixelSize: 20,
                    // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
                }
            });

        });


        this.weldDataSource.entities.add({
            position: Cesium.Cartesian3.fromDegrees(options.positions[0], options.positions[1], options.positions[2] + 5),
            id: options.id,
            billboard: {
                image: "../../../asset/materialImg/line-markder.png", // "../../../asset/materialImg/line-markder.png",
                width: 16,
                height: 102,
                sizeInMaters: true,
                // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                // scaleByDistance: new Cesium.NearFarScalar(1.5e2, 2.0, 1.5e7, 1),
                eyeOffset: new Cesium.Cartesian2(0.0, -1.0),
                // pixelOffsetScaleByDistance: new Cesium.NearFarScalar(1.5e2, 50, 8.0e6, 1.0),//根据距照相机的距离指定广告牌的像素偏移
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(20.0, 400.0),
            }
        })

        entity.billboard.disableDepthTestDistance = Number.POSITIVE_INFINITY; //去掉地形遮挡



        //         // 绘制label
        //         this.weldDataSource.entities.add({
        //             position: Cesium.Cartesian3.fromDegrees(options.positions[0], options.positions[1], options.positions[2] + 5),
        //             id: options.id,
        //             label: {
        //                 text: options.id.replace('Welding', ''),
        //                 color: Cesium.Color.fromCssColorString('#fff'),
        //                 font: 'normal 32px MicroSoft YaHei',
        //                 showBackground: true,
        //                 outlineColor :new Cesium.Color(0.0, 0.0, 0.0, 1.0),
        //                 outlineWidth : 2.0,
        //                 // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
        //                 scale: 0.5,
        //                 // fillColor: Cesium.Color.BLACK,        //字体颜色
        //                 fillColor: Cesium.Color.AQUA,        //字体颜色
        //                 // backgroundColor: Cesium.Color.AQUA,    //背景颜色
        //                 backgroundColor: new Cesium.Color(0.0, 0.0, 0.0, 0.1),    //背景颜色
        //                 horizontalOrigin: Cesium.HorizontalOrigin.LEFT_CLICK,
        //                 // pixelOffset: new Cesium.Cartesian2(0.0, -2.0),
        //                 showBackground: true,                //是否显示背景颜色
        //                 style: Cesium.LabelStyle.FILL,        //label样式
        //                 eyeOffset: new Cesium.Cartesian3(0, 0, -10),
        //                 // pixelOffsetScaleByDistance: new Cesium.NearFarScalar(1.5e2, 50, 8.0e6, 1.0),//根据距照相机的距离指定广告牌的像素偏移
        //                 distanceDisplayCondition: new Cesium.DistanceDisplayCondition(20.0, 400.0),
        //             }

        // // 　　 entity.billboard.disableDepthTestDistance = Number.POSITIVE_INFINITY; //去掉地形遮挡
        //             // ,
        //             // billboard: {
        //             //     image: "../../../asset/materialImg/line-markder.png", // "../../../asset/materialImg/line-markder.png",
        //             //     width: 16,
        //             //     height: 102,
        //             //     sizeInMaters: true,
        //             //     // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
        //             //     // scaleByDistance: new Cesium.NearFarScalar(1.5e2, 2.0, 1.5e7, 1),
        //             //     eyeOffset: new Cesium.Cartesian2(0.0, -1.0),
        //             //     // pixelOffsetScaleByDistance: new Cesium.NearFarScalar(1.5e2, 50, 8.0e6, 1.0),//根据距照相机的距离指定广告牌的像素偏移
        //             //     distanceDisplayCondition: new Cesium.DistanceDisplayCondition(20.0, 400.0),
        //             // }
        //         })
    }

}